package com.gcxy.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.gcxy.conf.result.R;
import com.gcxy.dto.LoginUserDTO;
import com.gcxy.entity.User;
import com.gcxy.mapper.UserMapper;
import com.gcxy.service.IUserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 用户表; 服务实现类
 * </p>
 *
 * @author author
 * @since 2024-12-25
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IUserService {
    @Override
    public R login(LoginUserDTO loginUserDTO) {
        //根据用户名从数据库中查询用户
        LambdaQueryWrapper<User> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(User::getUserId, loginUserDTO.getUserId());
        User user = this.getOne(queryWrapper);
        //判断用户是否存在
        if (user == null) {
            return R.Failed("用户名不存在");
        }
        //判断密码是否正确
        if (!user.getPassword().equals(Md5Utils.hash(loginUserDTO.getPassword()))) {
            return R.Failed("密码错误");
        }
        //返回token

        //密码正确把用户信息存入缓存中
        return null;
    }
}
